Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
@hapi/mimos
Advanced tools
@hapi/mimos is a utility library for handling and managing MIME types. It provides a way to look up MIME types based on file extensions, and vice versa, and allows for custom MIME type definitions.
Lookup MIME type by file extension
This feature allows you to look up the MIME type based on a file extension. In this example, the MIME type for a .txt file is retrieved.
const Mimos = require('@hapi/mimos');
const mimos = new Mimos();
const mimeType = mimos.path('file.txt');
console.log(mimeType); // { source: 'iana', compressible: true, charset: 'UTF-8', type: 'text/plain' }
Lookup file extension by MIME type
This feature allows you to look up the file extension based on a MIME type. In this example, the file extensions for the MIME type 'text/html' are retrieved.
const Mimos = require('@hapi/mimos');
const mimos = new Mimos();
const extension = mimos.type('text/html');
console.log(extension); // { source: 'iana', compressible: true, charset: 'UTF-8', type: 'text/html', extensions: [ 'html', 'htm' ] }
Custom MIME type definitions
This feature allows you to define custom MIME types. In this example, a custom MIME type 'application/x-custom' is defined and then retrieved based on the file extension.
const Mimos = require('@hapi/mimos');
const mimos = new Mimos({
override: {
'application/x-custom': {
source: 'custom',
compressible: true,
extensions: ['custom']
}
}
});
const customType = mimos.path('file.custom');
console.log(customType); // { source: 'custom', compressible: true, type: 'application/x-custom', extensions: [ 'custom' ] }
The 'mime' package is a popular library for working with MIME types. It provides similar functionality to @hapi/mimos, such as looking up MIME types based on file extensions and vice versa. However, it does not support custom MIME type definitions as flexibly as @hapi/mimos.
The 'mime-types' package is another library for handling MIME types. It offers a comprehensive list of MIME types and allows for looking up MIME types by extension and vice versa. It is similar to @hapi/mimos but does not provide the same level of customization for MIME type definitions.
mimos is part of the hapi ecosystem and was designed to work seamlessly with the hapi web framework and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out hapi – they work even better together.
FAQs
Mime database interface
The npm package @hapi/mimos receives a total of 678,306 weekly downloads. As such, @hapi/mimos popularity was classified as popular.
We found that @hapi/mimos demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.